package com.bci.pwtz.service.cad;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.log4j.Logger;

public class Cad_Line {
	public static int LOG_DEBUG = 0;
	public static int LOG_INFO = 1;
    private static Logger logger=Logger.getLogger(Cad_Line.class);
	public static final int line_bx = 3; // 表箱
	public static final int line_dl = 2; // 电缆
	public static final int line_dx = 1; // 导线
	public static final int line_xl = 0; // 线路
	public static final double texthight = 0.8D;
	public String layerName = "";
	public int line_type = 0;
	public String deviceName = "";
	Cad_Rect rect = new Cad_Rect(1);
	public String same_obj = "";
	public String showName = "";
	public boolean usesame = true;
	public String lineCode = ""; //Added by liusk jan-20/2015
	public String lineName = "";
	
	public static void Log(int type, String info){
		switch (type) {
		case 0 :
			if (logger.isDebugEnabled()) {
				logger.debug(info);
			}
		case 1 :
			if (logger.isInfoEnabled()) {
				logger.info(info);
			}
			break;
		case 2 :
			if (logger.isTraceEnabled()) {
				logger.trace(info);
			}
			break;
		case 3 :
			logger.warn(info);
			break;
		case 4 :
			logger.error(info);
			break;
		default:
			break;
		}
	}

	public static boolean _clear_lines_ports(ArrayList<Cad_BaseDevice> list1, 
			ArrayList<Cad_BaseDevice> list2) {
	    
		if (list1==null || list2==null || list1.size()<1 || list2.size()<1)  {
	      return false;
	    }
		return true;
		
//	    boolean bool1 = false;
//	    int i = 0;
//	    
//	    label24: Cad_BaseDevice baseDevice;
//	    
//	    Cad_Point point1;
//	    Cad_Point point2;
//	    ArrayList localArrayList;
//	    int m;
//	    Object localObject1;
//	    Object localObject2;
//	    int i2;
//	    if (i < list1.size())
//	    {
//	      baseDevice = (Cad_BaseDevice)list1.get(i);
//	      point1 = null;
//	      if (i > 0)
//	      {
//	        boolean bool3 = ((Cad_BaseDevice)list1.get(i - 1)).drawRect.pt2.equals(baseDevice.drawRect.pt1);
//	        point1 = null;
//	        if (bool3)
//	          point1 = baseDevice.drawRect.pt1;
//	      }
//	      int j = i + 1;
//	      int k = list1.size();
//	      point2 = null;
//	      if (j < k)
//	      {
//	        boolean bool2 = ((Cad_BaseDevice)list1.get(i + 1)).drawRect.pt1.equals(baseDevice.drawRect.pt2);
//	        point2 = null;
//	        if (bool2)
//	          point2 = baseDevice.drawRect.pt2;
//	      }
//	      localArrayList = _get_lines_link_on_line(baseDevice, list2);
//	      if (localArrayList != null)
//	      {
//	        if ((point1 != null) || (point2 != null))
//	          break label491;
//	        int i1 = localArrayList.size();
//	        m = 0;
//	        localObject1 = null;
//	        localObject2 = null;
//	        if (i1 > 1)
//	        {
//	          m = 1;
//	          localObject1 = ((Cad_BaseDevice)localArrayList.get(0)).drawRect.pt2;
//	          localObject2 = localObject1;
//	          i2 = 0;
//	          if (i2 < localArrayList.size())
//	            break label272;
//	        }
//	      }
//	    }
//	    label272: label491: 
//	    do
//	    {
//	      if (m != 0)
//	      {
//	        baseDevice.drawRect.set((Cad_Point)localObject1, (Cad_Point)localObject2, true);
//	        bool1 = true;
//	      }
//	      i++;
//	      break label24;
//	      
//	      break;
//	      if (!Cad_Rect.double_equals(((Cad_BaseDevice)localArrayList.get(i2)).drawRect.size().cx, 0.0D))
//	      {
//	        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.x > ((Cad_Point)localObject1).x)
//	          localObject1 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//	        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.x < ((Cad_Point)localObject2).x)
//	          localObject2 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//	      }
//	      while (true)
//	      {
//	        i2++;
//	        break;
//	        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.y > ((Cad_Point)localObject1).y)
//	          localObject1 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//	        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.y < ((Cad_Point)localObject2).y)
//	          localObject2 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//	      }
//	      if (point1 != null)
//	      {
//	        m = 0;
//	        localObject1 = null;
//	        if (point2 != null);
//	      }
//	      else
//	      {
//	        m = 1;
//	        if (point1 == null)
//	          break label591;
//	        localObject1 = point1;
//	      }
//	      localObject2 = null;
//	    }
//	    while (m == 0);
//	    
//	    label519: double d1 = 0.0D;
//	    Cad_Point point3 = null;
//	    for (int n = 0; n<localArrayList.size(); n++)
//	    {
//	      double d2 = _getjl((Cad_Point)localObject1, ((Cad_BaseDevice)localArrayList.get(n)).drawRect.pt2);
//	      if (d2 > d1)
//	      {
//	        d1 = d2;
//	        point3 = ((Cad_BaseDevice)localArrayList.get(n)).drawRect.pt2;
//	      }
//	    }
//	     localObject2 = null;
//	     if (point1 != null)
//	        {
//	          localObject2 = null;
//	          if (point2 == null)
//	          {
//	            localObject1 = point1;
//	            localObject2 = point3;
//	          }
//	        }
//	     if ((point1 != null) || (point2 == null))
//	          break;
//	     localObject1 = point3;
//	     localObject2 = point2;
//	     break;
//	     label591: localObject1 = point2;
//	     break label519;
	
//    boolean bool1 = false;
//    int i = 0;
//    
//    label24: Cad_BaseDevice baseDevice;
//    
//    Cad_Point point1;
//    Cad_Point point2;
//    ArrayList localArrayList;
//    int m;
//    Object localObject1;
//    Object localObject2;
//    int i2;
//    if (i < list1.size())
//    {
//      baseDevice = (Cad_BaseDevice)list1.get(i);
//      point1 = null;
//      if (i > 0)
//      {
//        boolean bool3 = ((Cad_BaseDevice)list1.get(i - 1)).drawRect.pt2.equals(baseDevice.drawRect.pt1);
//        point1 = null;
//        if (bool3)
//          point1 = baseDevice.drawRect.pt1;
//      }
//      int j = i + 1;
//      int k = list1.size();
//      point2 = null;
//      if (j < k)
//      {
//        boolean bool2 = ((Cad_BaseDevice)list1.get(i + 1)).drawRect.pt1.equals(baseDevice.drawRect.pt2);
//        point2 = null;
//        if (bool2)
//          point2 = baseDevice.drawRect.pt2;
//      }
//      localArrayList = _get_lines_link_on_line(baseDevice, list2);
//      if (localArrayList != null)
//      {
//        if ((point1 != null) || (point2 != null))
//          break label491;
//        int i1 = localArrayList.size();
//        m = 0;
//        localObject1 = null;
//        localObject2 = null;
//        if (i1 > 1)
//        {
//          m = 1;
//          localObject1 = ((Cad_BaseDevice)localArrayList.get(0)).drawRect.pt2;
//          localObject2 = localObject1;
//          i2 = 0;
//          if (i2 < localArrayList.size())
//            break label272;
//        }
//      }
//    }
//    label272: label491: 
//    do
//    {
//      if (m != 0)
//      {
//        baseDevice.drawRect.set((Cad_Point)localObject1, (Cad_Point)localObject2, true);
//        bool1 = true;
//      }
//      i++;
//      break label24;
//      break;
//      if (!Cad_Rect.double_equals(((Cad_BaseDevice)localArrayList.get(i2)).drawRect.size().cx, 0.0D))
//      {
//        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.x > ((Cad_Point)localObject1).x)
//          localObject1 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.x < ((Cad_Point)localObject2).x)
//          localObject2 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//      }
//      while (true)
//      {
//        i2++;
//        break;
//        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.y > ((Cad_Point)localObject1).y)
//          localObject1 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//        if (((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2.y < ((Cad_Point)localObject2).y)
//          localObject2 = ((Cad_BaseDevice)localArrayList.get(i2)).drawRect.pt2;
//      }
//      if (point1 != null)
//      {
//        m = 0;
//        localObject1 = null;
//        if (point2 != null);
//      }
//      else
//      {
//        m = 1;
//        if (point1 == null)
//          break label591;
//        localObject1 = point1;
//      }
//      localObject2 = null;
//    }
//    while (m == 0);
//    label519: double d1 = 0.0D;
//    Cad_Point point3 = null;
//    for (int n = 0; ; n++)
//    {
//      if (n >= localArrayList.size())
//      {
//        localObject2 = null;
//        if (point1 != null)
//        {
//          localObject2 = null;
//          if (point2 == null)
//          {
//            localObject1 = point1;
//            localObject2 = point3;
//          }
//        }
//        if ((point1 != null) || (point2 == null))
//          break;
//        localObject1 = point3;
//        localObject2 = point2;
//        break;
//        label591: localObject1 = point2;
//        break label519;
//      }
//      double d2 = _getjl((Cad_Point)localObject1, ((Cad_BaseDevice)localArrayList.get(n)).drawRect.pt2);
//      if (d2 > d1)
//      {
//        d1 = d2;
//        point3 = ((Cad_BaseDevice)localArrayList.get(n)).drawRect.pt2;
//      }
//    }

  }

	public static boolean _clear_pt_link_lines(ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2) {
		if (list1.size() < 2)
			return false;
		ArrayList localArrayList1 = _get_lines_link_on_line(
				(Cad_BaseDevice) list1.get(0), list2);
		
		return true;
//		boolean bool1 = false;
//		int k;
//		boolean bool2;
//		ArrayList localArrayList2;
//		if (localArrayList1 != null) {
//			bool1 = true;
//			k = 0;
//			if ((k < localArrayList1.size()) && (bool1))
//				;
//		} else {
//			if (bool1)
//				list1.remove(0);
//			int i = list1.size();
//			bool2 = false;
//			if (i > 1) {
//				localArrayList2 = _get_lines_link_on_line(
//						(Cad_BaseDevice) list1.get(-1 + list1.size()), list2);
//				bool2 = false;
//				if (localArrayList2 != null)
//					bool2 = true;
//			}
//		}
//		for (int j = 0;; j++) {
//			if ((j >= localArrayList2.size()) || (!bool2)) {
//				if (bool2)
//					list1.remove(-1 + list1.size());
//				if ((bool2) || (bool1))
//					break label232;
//				return false;
//				bool1 = ((Cad_BaseDevice) list1.get(0)).drawRect.pt2
//						.equals(((Cad_BaseDevice) localArrayList1.get(k)).drawRect.pt2);
//				k++;
//				break;
//			}
//			bool2 = ((Cad_BaseDevice) list1.get(-1 + list1.size())).drawRect.pt1
//					.equals(((Cad_BaseDevice) localArrayList2.get(j)).drawRect.pt2);
//		}
//		label232: return true;
	}

	public static boolean _clear_unuse_line(ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2) {
		if ((list1 == null) || (list2 == null))
			return false;
		if ((list2.size() < 1) || (list1.size() < 1))
			return false;
		ArrayList localArrayList = new ArrayList();
		for (int i = 0;; i++) {
			if (i >= list1.size()) {
				if (localArrayList.size() <= 0)
					break;
				list1.removeAll(localArrayList);
				return true;
			}
			int j = -1 + list1.size();
			int k = 0;
			if (i < j) {
				boolean bool = ((Cad_BaseDevice) list1.get(i)).drawRect.pt2
						.equals(((Cad_BaseDevice) list1.get(i + 1)).drawRect.pt1);
				k = 0;
				if (!bool)
					k = 1;
			}
			if ((k == 0)
					&& (i > 0)
					&& (!((Cad_BaseDevice) list1.get(i - 1)).drawRect.pt2
							.equals(((Cad_BaseDevice) list1.get(i)).drawRect.pt1)))
				k = 1;
			if ((i == 0) && (list1.size() == 1))
				k = 1;
			if ((k != 0)
					&& (_get_lines_link_on_line((Cad_BaseDevice) list1.get(i),
							list2) == null))
				localArrayList.add((Cad_BaseDevice) list1.get(i));
		}
		return false;
	}

	public static int _fxotherpts(boolean pBool, Cad_Point point, ArrayList<Cad_BaseDevice> list1, 
			ArrayList<Cad_BaseDevice> list2)  {
	    if (list1.size() < 0)
	      return 0;
	    if (list1.size() == 1)
	    {
	      Cad_BaseDevice baseDevice1 = new Cad_BaseDevice();
	      baseDevice1.drawRect.set(point, ((Cad_BaseDevice)list1.get(0)).drawRect.getlinkpt(point), true);
	      list2.add(baseDevice1);
	      return 1;
	    }
	    new ArrayList();
	    ArrayList localArrayList1 = new ArrayList();
	    ArrayList localArrayList2 = new ArrayList();
	    _setpt_link(list1, null, false);
	    _ptpl(list1, point);
	    int i = list1.size();
	    boolean bool = false;
	    int j = 0;
	    
	    Log(LOG_INFO,"_fxotherpts:"+"正在计算表箱拓扑连线..."+"list1.size()="+list1.size());
	    
	    ArrayList localArrayList5;
//	    while (true);
//	      if (_getpt_unlinkcn(list1) <= 0)
//	      {
//	  	    Log(LOG_INFO,"_fxotherpts:"+"完成表箱拓扑线计算!");
//	        _setpt_link(list1, null, false);
//	        _ptlx(list1, localArrayList1);
////	        localArrayList5 = _ptsfslx(list1, localArrayList1, list2, true, paramOper_info);
//	      }
//	      else
//	      {
//	        ArrayList localArrayList3 = new ArrayList();
//	        _ptfz(list1, localArrayList2);
//	        _ptlx(list1, localArrayList1);
//	        int k = _get_line1_fz_index(list1, localArrayList2, localArrayList1);
//	        Cad_BaseDevice baseDevice3;
//	        int i2;
//	        ArrayList localArrayList4;
//	        String str;
//	        int n;
////	        label284: int i1;
//	        if (list2.size() == 0)
//	        {
//	          baseDevice3 = _fxxd0(2.0D, pBool, list1, (ArrayList)localArrayList2.get(0));
//	          localArrayList3.add(baseDevice3);
//	          list2.add(baseDevice3);
//	          i2 = 1;
//	          if (i2 > k)
//	          {
//	            _zlxlxlk(list1, localArrayList1, localArrayList3);
//	            localArrayList4 = _ptsfslx(list1, localArrayList1, list2, bool, null);
//	            str = "";
//	            n = 0;
////	            if (n < localArrayList4.size())
////	              break label485;
////	            i1 = _getpt_unlinkcn(list1);
////	            if (i1 != i)
////	              break label603;
//	          }
//	        }
//	        label398: label410: label603: for (bool = true; ; bool = false)
//	        {
////	          i = i1;
////	          Oper_info.next(paramOper_info, list1.size() - i1);
////	          if (Oper_info.can_run(paramOper_info))
////	            break label609;
//	          return -1;
////	          baseDevice3 = _fxxd1(baseDevice3, 2.0D, list1, (ArrayList)localArrayList2.get(i2), localArrayList1);
////	          if (baseDevice3 != null)
////	          {
////	            if (_yxjc(list2, null, baseDevice3.drawRect) != null)
////	              break label398;
////	            localArrayList3.add(baseDevice3);
////	            list2.add(baseDevice3);
////	          }
////	          while (true)
////	          {
////	            i2++;
////	            break;
////	            baseDevice3 = null;
////	          }
////	          Cad_BaseDevice baseDevice2 = null;
////	          int m = 0;
////	          if (m <= k)
////	          {
////	            baseDevice2 = _fxxd1(baseDevice2, 2.0D, list1, (ArrayList)localArrayList2.get(m), localArrayList1);
////	            if (baseDevice2 != null)
////	            {
////	              if (_yxjc(list2, null, baseDevice2.drawRect) != null)
////	                break label479;
////	              localArrayList3.add(baseDevice2);
////	              list2.add(baseDevice2);
////	            }
////	          }
////	          while (true)
////	          {
////	            m++;
////	            break label410;
////	            break;
////	            label479: baseDevice2 = null;
////	          }
//////	          label485: Cad_Rect localCad_Rect = ((Cad_BaseDevice)localArrayList4.get(n)).drawRect;
//////	          StringBuilder localStringBuilder = new StringBuilder(String.valueOf(str));
//////	          Object[] arrayOfObject = new Object[4];
//////	          arrayOfObject[0] = Double.valueOf(localCad_Rect.pt1.x);
//////	          arrayOfObject[1] = Double.valueOf(localCad_Rect.pt1.y);
//////	          arrayOfObject[2] = Double.valueOf(localCad_Rect.pt2.x);
//////	          arrayOfObject[3] = Double.valueOf(localCad_Rect.pt2.y);
//////	          str = String.format("line %1$f,%2$f %3$f,%4$f  \r\n", arrayOfObject);
////	          n++;
////	          break label284;
////	        }
////	        label609: if (bool)
////	          j++;
////	        while (j > 3)
////	        {
////		  	    Log(LOG_INFO,"_fxotherpts:"+"无法连接所有表箱!");
////
////	          return -1;
////	          j = 0;
////	        }
//	      }
//	      }
//  	    Log(LOG_INFO,"_fxotherpts:"+"正在清理线段...");
//
////	    _clear_unuse_line(list2, localArrayList5);
//	    ArrayList localArrayList6 = _line_to_lines(list2);
//  	    Log(LOG_INFO,"_fxotherpts:"+"正在清理线头..."+"localArrayList6.size()="+localArrayList6.size());
////	    for (int i3 = 0; ; i3++)
//	    {
//	      if (i3 >= localArrayList6.size())
//	      {
////	        _selflink_mor_lines(list2, localArrayList6, list1, paramOper_info);
//	        return -1;
//	      }
////	      _clear_pt_link_lines((ArrayList)localArrayList6.get(i3), localArrayList5);
////	      _clear_lines_ports((ArrayList)localArrayList6.get(i3), localArrayList5);
//	    }
  	    Log(LOG_INFO,"_fxotherpts:"+"合并拓扑线!");
//	    if (localArrayList5 != null)
//	      list2.addAll(localArrayList5);
  	    Log(LOG_INFO,"_fxotherpts:"+"生成最终拓扑线!");
	    Cad_BaseDevice baseDevice4 = _pt_link_lines(null, point, list2, list1, null);
//	    if (baseDevice4 != null)
//	      list2.add(baseDevice4);
//	    return list2.size();
	    return 0;
	}

	private static Cad_BaseDevice _fxxd0(double db, boolean pBool,
			ArrayList<Cad_BaseDevice> list1, ArrayList<Cad_BaseDevice> list2) {
		if ((list1 == null) || (list2 == null))
			;
		while (list2.size() < 2)
			return null;
		Cad_Rect localCad_Rect1 = new Cad_Rect(
				((Cad_BaseDevice) list2.get(0)).linkPoint,
				((Cad_BaseDevice) list2.get(-1 + list2.size())).linkPoint);
		Cad_Rect localCad_Rect2 = _getlineqsline(_getMAXdxypy(list2),
				localCad_Rect1, pBool, db);
		_setpt_link(list1, list2, true);
		Cad_BaseDevice baseDevice = new Cad_BaseDevice();
		baseDevice.drawRect.set(localCad_Rect2);
		baseDevice.drawRect.rectType = 1;
		return baseDevice;
	}

	private static Cad_BaseDevice _fxxd1(Cad_BaseDevice paramEx_unbas,
			double db, ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2, ArrayList<Cad_BaseDevice> list3) {
//		if ((list1 == null) || (list2 == null) || (list3 == null))
//			return null;
//		if (list2.size() < 2)
//			return null;
//		Cad_BaseDevice baseDevice = new Cad_BaseDevice();
//		Cad_Rect localCad_Rect1 = new Cad_Rect(
//				((Cad_BaseDevice) list2.get(0)).linkPoint,
//				((Cad_BaseDevice) list2.get(-1 + list2.size())).linkPoint);
//		Cad_Rect localCad_Rect2 = _getMAXdxypy(list2);
//		Object localObject = _getlineqsline(localCad_Rect2, localCad_Rect1,
//				false, db);
//		Cad_Rect localCad_Rect3 = _getlineqsline(localCad_Rect2,
//				localCad_Rect1, false, db);
//		if (paramEx_unbas != null) {
//			baseDevice.drawRect.pt1.copy(paramEx_unbas.drawRect.pt2);
//			baseDevice.drawRect.pt2.copy(((Cad_Rect) localObject).pt2);
//			if ((_yxjc(list3, null, baseDevice.drawRect, false))
//					|| (_ydjc(list1, null, baseDevice.drawRect))) {
//				localObject = _getlineqsline(localCad_Rect2, localCad_Rect1,
//						true, db);
//				if ((_yxjc(list3, null, (Cad_Rect) localObject, false))
//						|| (_ydjc(list1, null, (Cad_Rect) localObject)))
//					if ((_yxjc(list3, null, localCad_Rect3, false))
//							|| (_ydjc(list1, null, localCad_Rect3)))
//						break label274;
//			}
//		}
//		label274: for (localObject = localCad_Rect3;; localObject = null) {
//			if (localObject == null)
//				break label280;
//			baseDevice.drawRect.set((Cad_Rect) localObject);
//			_setpt_link(list1, list2, true);
//			return baseDevice;
//			baseDevice.drawRect.pt1.copy(((Cad_Rect) localObject).pt1);
//			break;
//		}
//		label280: return null;
		return null;
	}

	private static Cad_Rect _getLineMAXDxyforPts(ArrayList<Cad_Point> list, Cad_Rect rect)
	{
		return null;
//    Cad_Rect localCad_Rect = null;
//    if (list == null);
//    do
//    {
//      int i;
//      do
//      {
//        return localCad_Rect;
//        i = list.size();
//        localCad_Rect = null;
//      }
//      while (i < 1);
//      localCad_Rect = new Cad_Rect();
//    }
//    while (list.size() <= 2);
//    int j = 0;
//    label39: Cad_Point point1;
//    Cad_Point point2;
//    if (j < list.size())
//    {
//      point1 = (Cad_Point)list.get(j);
//      point2 = Cad_Rect._getPLcz(rect, point1);
//      if (point1.x >= point2.x)
//        break label193;
//      if (localCad_Rect.pt1.x < Math.abs(point1.x - point2.x))
//        localCad_Rect.pt1.x = Math.abs(point1.x - point2.x);
//      label127: if (point1.y >= point2.y)
//        break label256;
//      if (localCad_Rect.pt1.y >= Math.abs(point1.y - point2.y));
//    }
//    label256: for (localCad_Rect.pt1.y = Math.abs(point1.y - point2.y); ; localCad_Rect.pt2.y = Math.abs(point1.y - point2.y))
//      label193: 
//      do
//      {
//        j++;
//        break label39;
//        break;
//        if ((point1.x <= point2.x) || (localCad_Rect.pt2.x >= Math.abs(point1.x - point2.x)))
//          break label127;
//        localCad_Rect.pt2.x = Math.abs(point1.x - point2.x);
//        break label127;
//      }
//      while ((point1.y <= point2.y) || (localCad_Rect.pt2.y >= Math.abs(point1.y - point2.y)));
  }

	private static Cad_Rect _getMAXdxypy(ArrayList<Cad_BaseDevice> list) {
		if (list == null)
			return null;
		ArrayList localArrayList = new ArrayList();
		for (int i = 0;; i++) {
			if (i >= list.size())
				return _getLineMAXDxyforPts(
						localArrayList,
						new Cad_Rect(
								((Cad_BaseDevice) list.get(0)).linkPoint,
								((Cad_BaseDevice) list.get(-1 + list.size())).linkPoint));
			Cad_BaseDevice baseDevice = (Cad_BaseDevice) list.get(i);
			Cad_Point point1 = new Cad_Point();
			point1.copy(baseDevice.drawRect.leftbottom());
			localArrayList.add(point1);
			Cad_Point point2 = new Cad_Point();
			point2.copy(baseDevice.drawRect.rightbottom());
			localArrayList.add(point2);
			Cad_Point point3 = new Cad_Point();
			point3.copy(baseDevice.drawRect.righttop());
			localArrayList.add(point3);
			Cad_Point point4 = new Cad_Point();
			point4.copy(baseDevice.drawRect.lefttop());
			localArrayList.add(point4);
		}
	}

	public static int _get_line1_fz_index(ArrayList<Cad_BaseDevice> list1,
			ArrayList<ArrayList<Cad_BaseDevice>> list,
			ArrayList<Cad_BaseDevice> list2) {
		Cad_BaseDevice baseDevice = null;
		int i = 0;
		int j = 0 ;
		
		for(i=0; i<list2.size(); i++) {
			if (((Cad_BaseDevice) list2.get(i)).linked)
				baseDevice = (Cad_BaseDevice) list1.get(i);
			for (int k = 0; k<list.size(); k++) {
				ArrayList localArrayList = (ArrayList) list.get(k);
				if (localArrayList.indexOf(baseDevice) == -1
						+ localArrayList.size())
					j = k;
				break;
			}
		} 

		if ((i >= list2.size()) || (baseDevice != null)) {
			if (baseDevice == null)
				baseDevice = (Cad_BaseDevice) list1.get(-1 + list1.size());
			j = 0;
		}

		return j;
		
//		int i = 0;
//		int j;
//		if ((i >= list2.size()) || (baseDevice != null)) {
//			if (baseDevice == null)
//				baseDevice = (Cad_BaseDevice) list1.get(-1 + list1.size());
//			j = 0;
//		}
//		for (int k = 0;; k++) {
//			if (k >= list.size()) {
//				return j;
//				if (((Cad_BaseDevice) list2.get(i)).linked)
//					baseDevice = (Cad_BaseDevice) list1.get(i);
//				i++;
//				break;
//			}
//			ArrayList localArrayList = (ArrayList) list.get(k);
//			if (localArrayList.indexOf(baseDevice) == -1
//					+ localArrayList.size())
//				j = k;
//		}
	}

	public static ArrayList<Cad_BaseDevice> _get_lines_link_on_line(
			Cad_BaseDevice paramEx_unbas, ArrayList<Cad_BaseDevice> list) {
		ArrayList localArrayList = new ArrayList();
//		int i = 0;
//		if (i >= list.size()) {
//			if (localArrayList.size() > 0)
//				return localArrayList;
//		} else {
//			Cad_BaseDevice baseDevice = (Cad_BaseDevice) list.get(i);
//			int k;
//			if (Cad_Rect._ptOnLine(paramEx_unbas.drawRect,
//					baseDevice.drawRect.pt1) == 1) {
//				k = 1;
//				baseDevice.linkPoint = baseDevice.drawRect.pt1;
//			}
//			while (true) {
//				if (k != 0)
//					localArrayList.add((Cad_BaseDevice) list.get(i));
//				i++;
//				break;
//				int j = Cad_Rect._ptOnLine(paramEx_unbas.drawRect,
//						baseDevice.drawRect.pt2);
//				k = 0;
//				if (j == 1) {
//					k = 1;
//					baseDevice.linkPoint = baseDevice.drawRect.pt2;
//				}
//			}
//		}
		return null;
	}

	public static ArrayList<Cad_BaseDevice> _get_unlink_pts(
			ArrayList<Cad_BaseDevice> list) {
		if (list == null) {
			return null;
		}
		ArrayList<Cad_BaseDevice> localObject = new ArrayList<Cad_BaseDevice> ();
		for (int i = 0; i<list.size(); i++) {
			if (!list.get(i).linked) {
				localObject.add(list.get(i)); 
				}
		}
		if (localObject.size() > 0) {
			return localObject;
		}
		else {
			return null;
		}
//		Object localObject = new ArrayList();
//		for (int i = 0;; i++) {
//			if (i >= list.size()) {
//				if (((ArrayList) localObject).size() > 0)
//					break;
//				return null;
//			}
//			if (!((Cad_BaseDevice) list.get(i)).linked)
//				((ArrayList) localObject).add((Cad_BaseDevice) list.get(i));
//		}
	}

	public static double _getjl(Cad_Point point1, Cad_Point point2) {
		if (point1.equals(point2)) {
			return 0.0D;
		}
		return Math.sqrt(Math.pow(point1.x - point2.x, 2.0D)
				+ Math.pow(point1.y - point2.y, 2.0D));
	}

	public static double _getjl(Cad_Rect rect) {
		return _getjl(rect.pt1, rect.pt2);
	}

	private static Cad_Rect _getlineqsline(Cad_Rect paramCad_Rect1, Cad_Rect paramCad_Rect2, boolean pBool, double db)
  {
		return null;
//    if ((paramCad_Rect1 == null) || (paramCad_Rect2 == null))
//      return null;
//    double d1;
//    double d2;
//    double d3;
//    double d4;
//    double d5;
//    label97: double d6;
//    double d7;
//    if (paramCad_Rect2.size().cx != 0.0D)
//    {
//      d1 = (paramCad_Rect2.pt1.y - paramCad_Rect2.pt2.y) / (paramCad_Rect2.pt1.x - paramCad_Rect2.pt2.x);
//      d2 = 1.0D;
//      d3 = 1.0D;
//      d4 = 1.0D;
//      d5 = d4;
//      if (!pBool)
//        break label279;
//      if (d1 >= 0.0D)
//        break label196;
//      d2 = paramCad_Rect1.pt2.x;
//      d3 = paramCad_Rect1.pt2.y;
//      d6 = 0.0D;
//      d7 = 0.0D;
//      if ((d2 == 0.0D) || (d3 == 0.0D))
//        break label413;
//      d6 = Math.sqrt(d3 * (d3 * (db * db)) / (d2 * d2 + d3 * d3));
//      d7 = d6 * Math.abs(d2 / d3);
//    }
//    while (true)
//    {
//      Cad_Rect localCad_Rect = new Cad_Rect(paramCad_Rect2);
//      localCad_Rect.moveof(d2 + d7 * d5, d3 + d6 * d4);
//      return localCad_Rect;
//      d1 = 0.0D;
//      break;
//      label196: if (d1 > 0.0D)
//      {
//        d5 = -1.0D;
//        d2 = -paramCad_Rect1.pt1.x;
//        d3 = paramCad_Rect1.pt2.y;
//        break label97;
//      }
//      if (d1 != 0.0D)
//        break label97;
//      if (paramCad_Rect2.size().cx == 0.0D)
//      {
//        d3 = 0.0D;
//        d2 = paramCad_Rect1.pt2.x;
//        break label97;
//      }
//      d2 = 0.0D;
//      d3 = paramCad_Rect1.pt2.y;
//      break label97;
//      label279: if (d1 < 0.0D)
//      {
//        d4 = -1.0D;
//        d5 = d4;
//        d2 = -paramCad_Rect1.pt1.x;
//        d3 = -paramCad_Rect1.pt1.y;
//        break label97;
//      }
//      if (d1 > 0.0D)
//      {
//        d2 = paramCad_Rect1.pt2.x;
//        d3 = -paramCad_Rect1.pt1.y;
//        d4 = -1.0D;
//        break label97;
//      }
//      if (d1 != 0.0D)
//        break label97;
//      if (paramCad_Rect2.size().cx == 0.0D)
//      {
//        d3 = 0.0D;
//        d2 = -paramCad_Rect1.pt1.x;
//        d5 = -1.0D;
//        break label97;
//      }
//      d2 = 0.0D;
//      d3 = -paramCad_Rect1.pt1.y;
//      d4 = -1.0D;
//      break label97;
//      label413: if (d2 == 0.0D)
//        d6 = db;
//      else
//        d7 = db;
//    }
  }

	public static Cad_Point _getpoint(Cad_Rect rect, Cad_Point point, double db) {
		if (rect.pt1.equals(rect.pt2))
			;
		while ((!rect.pt1.equals(point)) && (!rect.pt2.equals(point)))
			return null;
		double d1 = _getjl(rect.pt1, rect.pt2);
		double d2 = 1.0D;
		double d3 = 1.0D;
		if (point.x > rect.left)
			d2 = -1.0D;
		if (point.y > rect.bottom)
			d3 = -1.0D;
		Cad_Point point1 = new Cad_Point();
		point1.x = (d2 * (db * rect.size().cx / d1) + point.x);
		point1.y = (d3 * (db * rect.size().cy / d1) + point.y);
		return point1;
	}

	public static int _getpt_unlinkcn(ArrayList<Cad_BaseDevice> list) {
		return 0;
	}
//		int i;
//		if (list == null)
//			i = 0;
//		while (true) {
//			return i;
//			i = 0;
//			for (int j = 0; j < list.size(); j++)
//				if (!((Cad_BaseDevice) list.get(j)).linked)
//					i++;
//		}
//	}

	public static Cad_BaseDevice _line_link_lines(Cad_BaseDevice paramEx_unbas,
			ArrayList<Cad_BaseDevice> list1, ArrayList<Cad_BaseDevice> list2) {
		return null;
//		Object localObject = null;
//		Cad_BaseDevice baseDevice1 = new Cad_BaseDevice();
//		Cad_Point[] arrayOfEx_dpoint = new Cad_Point[4];
//		arrayOfEx_dpoint[0] = paramEx_unbas.drawRect.pt1;
//		arrayOfEx_dpoint[1] = paramEx_unbas.drawRect.pt2;
//		paramEx_unbas.drawRect.rectType = 1;
//		arrayOfEx_dpoint[2] = paramEx_unbas.drawRect.center();
//		double d1 = 1000000.0D;
//		int i = 0;
//		if (i >= 3)
//			return localObject;
//		for (int j = 0;; j++) {
//			if (j >= list1.size()) {
//				i++;
//				break;
//			}
//			Cad_BaseDevice baseDevice2 = _pt_link_line(null,
//					arrayOfEx_dpoint[i], (Cad_BaseDevice) list1.get(j), list2,
//					null);
//			if (baseDevice2 != null) {
//				double d3 = _getjl(baseDevice2.drawRect);
//				if (d3 < d1) {
//					d1 = d3;
//					localObject = baseDevice2;
//				}
//			}
//			if (i == 2) {
//				arrayOfEx_dpoint[3] = Cad_Rect._getLLjc(paramEx_unbas.drawRect,
//						((Cad_BaseDevice) list1.get(j)).drawRect);
//				if ((arrayOfEx_dpoint[3] != null)
//						&& (Cad_Rect._ptOnLine(
//								((Cad_BaseDevice) list1.get(j)).drawRect,
//								arrayOfEx_dpoint[3]) == 1)) {
//					baseDevice1.drawRect.set(
//							arrayOfEx_dpoint[3],
//							_pt_line_nearpt(arrayOfEx_dpoint[3],
//									paramEx_unbas.drawRect), true);
//					if (!_ydjc(list2, null, baseDevice1.drawRect)) {
//						double d2 = _getjl(baseDevice1.drawRect);
//						if (d2 < d1) {
//							d1 = d2;
//							localObject = baseDevice1;
//						}
//					}
//				}
//			}
//		}
	}

	public static ArrayList<ArrayList<Cad_BaseDevice>> _line_to_lines(
			ArrayList<Cad_BaseDevice> list) {
			return null;
//		Object localObject;
//		if (list == null)
//			localObject = null;
//		ArrayList localArrayList;
//		int i;
//		do {
//			return localObject;
//			if (list.size() < 1)
//				return null;
//			localObject = new ArrayList();
//			localArrayList = new ArrayList();
//			i = 0;
//			if (i < -1 + list.size())
//				break;
//			if (list.size() == 1) {
//				localArrayList.addAll(list);
//				((ArrayList) localObject).add(localArrayList);
//			}
//		} while (((ArrayList) localObject).size() > 0);
//		return null;
//		Cad_BaseDevice baseDevice1 = (Cad_BaseDevice) list.get(i);
//		Cad_BaseDevice baseDevice2 = (Cad_BaseDevice) list.get(i + 1);
//		localArrayList.add(baseDevice1);
//		if (!baseDevice1.drawRect.pt2.equals(baseDevice2.drawRect.pt1)) {
//			((ArrayList) localObject).add(localArrayList);
//			localArrayList = new ArrayList();
//			if (i == -2 + list.size()) {
//				localArrayList.add(baseDevice2);
//				((ArrayList) localObject).add(localArrayList);
//			}
//		}
//		while (true) {
//			i++;
//			break;
//			if (i == -2 + list.size()) {
//				localArrayList.add(baseDevice2);
//				((ArrayList) localObject).add(localArrayList);
//			}
//		}
	}

	public static Cad_BaseDevice _lines_link_lines(
			ArrayList<Cad_BaseDevice> list1, ArrayList<Cad_BaseDevice> list2,
			ArrayList<Cad_BaseDevice> list3) {
		Cad_BaseDevice localObject = null;
		double d1 = 1000000.0D;
		for (int i = 0;; i++) {
			if (i >= list1.size())
				return localObject;
			Cad_BaseDevice baseDevice = _line_link_lines(
					(Cad_BaseDevice) list1.get(i), list2, list3);
			if (baseDevice != null) {
				double d2 = _getjl(baseDevice.drawRect);
				if (d2 < d1) {
					d1 = d2;
					localObject = baseDevice;
				}
			}
		}
	}

	public static boolean _mk_rect_line(ArrayList<Cad_BaseDevice> list,
			ArrayList<Cad_Rect> list1) {
		if ((list == null) || (list1 == null))
			return false;
		for (int i = 0;; i++) {
			if (i >= list.size()) {
				if (list1.size() <= 0)
					break;
				return true;
			}
			list1.add(((Cad_BaseDevice) list.get(i)).drawRect);
		}
		return false;
	}

	public static Cad_Point _pt_line_nearpt(Cad_Point point, Cad_Rect rect) {
		Cad_Point point1 = new Cad_Point();
		if (_getjl(rect.pt1, point) > _getjl(rect.pt2, point)) {
			point1.copy(rect.pt2);
			return point1;
		}
		point.copy(rect.pt1);
		return point1;
	}

	public static Cad_BaseDevice _pt_link_line(Cad_BaseDevice paramEx_unbas1,
			Cad_Point point, Cad_BaseDevice paramEx_unbas2,
			ArrayList<Cad_BaseDevice> list1, ArrayList<Cad_BaseDevice> list2) {
		return null;
//		Cad_BaseDevice baseDevice = null;
//		Cad_BaseDevice[] arrayOfEx_unbas = new Cad_BaseDevice[4];
//		Cad_Point[] arrayOfEx_dpoint = new Cad_Point[4];
//		Cad_Rect localCad_Rect = new Cad_Rect();
//		localCad_Rect.set(paramEx_unbas2.drawRect.pt1,
//				paramEx_unbas2.drawRect.pt2, true);
//		int i = 4;
//		arrayOfEx_dpoint[0] = localCad_Rect.pt1;
//		arrayOfEx_dpoint[1] = localCad_Rect.pt2;
//		arrayOfEx_dpoint[2] = localCad_Rect.center();
//		arrayOfEx_dpoint[3] = Cad_Rect._getPLscz(localCad_Rect, point);
//		if (arrayOfEx_dpoint[3] == null)
//			i = 3;
//		int j = 0;
//		int k = 0;
//		double d;
//		if (k >= i)
//			d = 1000000.0D;
//		for (int m = 0;; m++) {
//			if (m >= j) {
//				return baseDevice;
//				arrayOfEx_unbas[j] = new Cad_BaseDevice();
//				arrayOfEx_unbas[j].drawRect.set(point, arrayOfEx_dpoint[k],
//						true);
//				if (!_ydjc(list1, paramEx_unbas1, arrayOfEx_unbas[j].drawRect)) {
//					if (list2 == null)
//						break label203;
//					if (!_yxjc(list2, point, arrayOfEx_unbas[j].drawRect, false))
//						j++;
//				}
//				while (true) {
//					k++;
//					break;
//					label203: j++;
//				}
//			}
//			if (d > _getjl(arrayOfEx_unbas[m].drawRect)) {
//				d = _getjl(arrayOfEx_unbas[m].drawRect);
//				baseDevice = arrayOfEx_unbas[m];
//			}
//		}
	}

	public static Cad_BaseDevice _pt_link_lines(Cad_BaseDevice paramEx_unbas,
			Cad_Point point, ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2, ArrayList<Cad_BaseDevice> list3) {
		Cad_BaseDevice localObject = null;
		double d1 = 100000.0D;
		for (int i = 0; i<list1.size(); i++) {
			Cad_BaseDevice baseDevice = _pt_link_line(paramEx_unbas, point,
					(Cad_BaseDevice) list1.get(i), list2, list3);
			if (baseDevice != null) {
				double d2 = _getjl(baseDevice.drawRect);
				if (d2 < d1) {
					d1 = d2;
					localObject = baseDevice;
				}
			}
		}
		return localObject;
//		for (int i = 0;; i++) {
//			if (i >= list1.size())
//				return localObject;
//			Cad_BaseDevice baseDevice = _pt_link_line(paramEx_unbas, point,
//					(Cad_BaseDevice) list1.get(i), list2, list3);
//			if (baseDevice != null) {
//				double d2 = _getjl(baseDevice.drawRect);
//				if (d2 < d1) {
//					d1 = d2;
//					localObject = baseDevice;
//				}
//			}
//		}
	}

	public static boolean _ptfz(ArrayList<Cad_BaseDevice> list,
			ArrayList<ArrayList<Cad_BaseDevice>> list1) {
		if ((list == null) || (list1 == null))
			return false;
		return false;
//		list1.clear();
//		ArrayList localArrayList1 = _get_unlink_pts(list);
//		if (_getpt_unlinkcn(localArrayList1) < 3) {
//			if (localArrayList1 != null)
//				list1.add(localArrayList1);
//			return list1.size() > 0;
//		}
//		ArrayList localArrayList2 = new ArrayList();
//		int i = 1;
//		double d1 = 0.0D;
//		int j = 0;
//		int k = 0;
//		int m = 0;
//		if (m >= -1 + localArrayList1.size())
//			return false;
//		Cad_BaseDevice baseDevice1 = (Cad_BaseDevice) localArrayList1.get(m);
//		Cad_BaseDevice baseDevice2 = (Cad_BaseDevice) localArrayList1
//				.get(m + 1);
//		if (i != 0)
//			if (baseDevice1.linkPoint.x - baseDevice2.linkPoint.x > 0.0D) {
//				k = 1;
//				label138: if (baseDevice1.linkPoint.y
//						- baseDevice2.linkPoint.y <= 0.0D)
//					break label262;
//				j = 1;
//				label163: d1 = Math.abs(baseDevice1.linkPoint.x
//						- baseDevice2.linkPoint.x)
//						/ Math.abs(baseDevice1.linkPoint.y
//								- baseDevice2.linkPoint.y);
//				localArrayList2.add(baseDevice1);
//				localArrayList2.add(baseDevice2);
//				int i2 = m + 1;
//				int i3 = -1 + localArrayList1.size();
//				i = 0;
//				if (i2 == i3)
//					list1.add(localArrayList2);
//			}
//		while (true) {
//			m++;
//			break;
//			k = 0;
//			break label138;
//			label262: j = 0;
//			break label163;
//			int n;
//			if (baseDevice1.linkPoint.x - baseDevice2.linkPoint.x > 0.0D) {
//				n = 1;
//				label293: if (baseDevice1.linkPoint.y
//						- baseDevice2.linkPoint.y <= 0.0D)
//					break label435;
//			}
//			label435: for (int i1 = 1;; i1 = 0) {
//				double d2 = Math.abs(baseDevice1.linkPoint.x
//						- baseDevice2.linkPoint.x)
//						/ Math.abs(baseDevice1.linkPoint.y
//								- baseDevice2.linkPoint.y) / d1;
//				if ((k != n) || (j != i1) || (d2 <= 1.0D - 0.8D)
//						|| (d2 >= 1.0D + 0.8D))
//					break label441;
//				localArrayList2.add(baseDevice2);
//				if (m + 1 != -1 + localArrayList1.size())
//					break;
//				list1.add(localArrayList2);
//				break;
//				n = 0;
//				break label293;
//			}
//			label441: i = 1;
//			list1.add(localArrayList2);
//			localArrayList2 = new ArrayList();
//			if (m > 0)
//				m--;
//		}
	}

	public static boolean _ptlx(ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2) {
		if ((list1 == null) || (list2 == null))
			return false;
		if (list1.size() < 2)
			return false;
		ArrayList localArrayList = _get_unlink_pts(list1);
		list2.clear();
		for (int i = 0;; i++) {
			if (i >= -1 + localArrayList.size()) {
				if (list2.size() <= 0)
					break;
				return true;
			}
			Cad_BaseDevice baseDevice = new Cad_BaseDevice();
			baseDevice.drawRect.pt1.copy(((Cad_BaseDevice) localArrayList
					.get(i)).linkPoint);
			baseDevice.drawRect.pt2.copy(((Cad_BaseDevice) localArrayList
					.get(i + 1)).linkPoint);
			baseDevice.linked = _yxjc(list2,
					((Cad_BaseDevice) localArrayList.get(i)).linkPoint,
					baseDevice.drawRect, false);
			if (baseDevice.linked)
				baseDevice.linkPoint = baseDevice.drawRect.pt1;
			list2.add(baseDevice);
		}
		return false;
	}

	public static boolean _ptpl(ArrayList<Cad_BaseDevice> list, Cad_Point point) {
		if ((list == null) || (point == null))
			;
		while (list.size() < 1)
			return false;
		if (list.size() < 2)
			return true;
		ArrayList localArrayList1 = new ArrayList();
		ArrayList localArrayList2 = new ArrayList();
		localArrayList1.addAll(list);
		Cad_Point point1 = point;
		if (localArrayList1.size() <= 0) {
			list.clear();
			list.addAll(localArrayList2);
			return true;
		}
		double d = 1000000.0D;
		int i = 0;
		for (int j = 0;; j++) {
			if (j >= localArrayList1.size()) {
				point1 = ((Cad_BaseDevice) localArrayList1.get(i)).linkPoint;
				localArrayList2.add((Cad_BaseDevice) localArrayList1.get(i));
				localArrayList1.remove(i);
				break;
			}
			if (_getjl(point1,
					((Cad_BaseDevice) localArrayList1.get(j)).linkPoint) < d) {
				d = _getjl(point1,
						((Cad_BaseDevice) localArrayList1.get(j)).linkPoint);
				i = j;
			}
		}
		return false;
	}

	public static ArrayList<Cad_BaseDevice> _ptsfslx(ArrayList<Cad_BaseDevice> list1, ArrayList<Cad_BaseDevice> list2, ArrayList<Cad_BaseDevice> list3, boolean pBool, Oper_info paramOper_info)
  {
    if ((list1 == null) || (list2 == null) || (list3 == null))
      return null;
    return null;
//    ArrayList localArrayList1 = new ArrayList();
//    _mk_rect_line(list3, localArrayList1);
//    ArrayList localArrayList2 = new ArrayList();
//    ArrayList localArrayList3 = new ArrayList();
//    localArrayList3.addAll(list3);
//    Cad_Rect localCad_Rect1 = new Cad_Rect();
//    Cad_Rect localCad_Rect2 = new Cad_Rect();
//    Oper_info.startoi(paramOper_info, list1.size(), "正在计算表箱拓扑线");
//    label304: label859: for (int i = 0; ; i++)
//    {
//      if (i >= list1.size())
//      {
//        Oper_info.msg(paramOper_info, "完成表箱拓扑线计算!");
//        return localArrayList2;
//      }
//      if (!((Cad_BaseDevice)list1.get(i)).linked)
//      {
//        Cad_Point point1 = ((Cad_BaseDevice)list1.get(i)).linkPoint;
//        int j = Cad_Rect._pt_near_line(point1, localArrayList1, true);
//        int k = Cad_Rect._pt_lines_nearline(point1, localArrayList1);
//        Cad_Rect localCad_Rect4;
//        if (j > -1)
//        {
//          localCad_Rect4 = (Cad_Rect)localArrayList1.get(j);
//          Cad_Point point3 = Cad_Rect._getPLscz(localCad_Rect4, point1);
//          localCad_Rect1.pt1.copy(point1);
//          if (Cad_Rect._ptOnLine(localCad_Rect4, point3) != 1)
//            break label670;
//          localCad_Rect1.pt2.copy(point3);
//          if ((_yxjc(list2, point1, localCad_Rect1, false)) || (_ydjc(list1, (Cad_BaseDevice)list1.get(i), localCad_Rect1)))
//            j = -1;
//        }
//        Cad_Rect localCad_Rect3;
//        if (k > -1)
//        {
//          localCad_Rect3 = (Cad_Rect)localArrayList1.get(k);
//          Cad_Point point2 = Cad_Rect._getPLscz(localCad_Rect3, point1);
//          localCad_Rect2.pt1.copy(point1);
//          if (Cad_Rect._ptOnLine(localCad_Rect3, point2) != 1)
//            break label688;
//          localCad_Rect2.pt2.copy(point2);
//          if ((_yxjc(list2, point1, localCad_Rect2, false)) || (_ydjc(list1, (Cad_BaseDevice)list1.get(i), localCad_Rect2)))
//            k = -1;
//        }
//        //label370: 
//        	Cad_BaseDevice baseDevice1;
//        Object localObject;
//        if ((j > -1) && (k > -1))
//        {
//          if (_getjl(localCad_Rect1) > _getjl(localCad_Rect2))
//            localCad_Rect1.set(localCad_Rect2);
//          if (!pBool)
//          {
//            int m = k;
//            baseDevice1 = null;
//            if (m == -2);
//          }
//          else
//          {
//            baseDevice1 = _pt_link_lines((Cad_BaseDevice)list1.get(i), ((Cad_BaseDevice)list1.get(i)).linkPoint, list3, list1, list2);
//          }
//          if (k != -2)
//            break label741;
//          localObject = null;
//          if (pBool)
//          {
//            localObject = null;
//            if (baseDevice1 != null)
//            {
//              localObject = new Cad_BaseDevice();
//              ((Cad_BaseDevice)localObject).drawRect.set(baseDevice1.drawRect);
//              ((Cad_BaseDevice)localObject).drawRect.set(((Cad_BaseDevice)list1.get(i)).drawRect.getlinkpt(((Cad_BaseDevice)localObject).drawRect.pt2), ((Cad_BaseDevice)localObject).drawRect.pt2, true);
//              ((Cad_BaseDevice)list1.get(i)).linked = true;
//            }
//          }
//        }
//        while (true)
//        {
//          if ((localObject == null) && (pBool))
//          {
//            Cad_BaseDevice baseDevice3 = _pt_link_lines((Cad_BaseDevice)list1.get(i), ((Cad_BaseDevice)list1.get(i)).linkPoint, localArrayList3, list1, null);
//            if (baseDevice3 != null)
//            {
//              ((Cad_BaseDevice)list1.get(i)).linked = true;
//              localArrayList2.add(baseDevice3);
//            }
//            localObject = baseDevice3;
//          }
//          if (localObject != null)
//          {
//            Cad_BaseDevice baseDevice2 = new Cad_BaseDevice();
//            baseDevice2.drawRect.rectType = 1;
//            baseDevice2.drawRect.pt1.copy(point1);
//            baseDevice2.drawRect.pt2.copy(((Cad_BaseDevice)localObject).drawRect.center());
//            localArrayList3.add(baseDevice2);
//          }
//          Oper_info.next(paramOper_info, list1.size() - _getpt_unlinkcn(list1));
//          if (Oper_info.can_run(paramOper_info))
//            break label859;
//          return null;
//          localCad_Rect1.pt2.copy(_pt_line_nearpt(point1, localCad_Rect4));
//          break;
//          localCad_Rect2.pt2.copy(_pt_line_nearpt(point1, localCad_Rect3));
//          break label304;
//          if (k > -1)
//          {
//            localCad_Rect1.set(localCad_Rect2);
//            break label370;
//          }
//          if ((k != -1) || (j != -1))
//            break label370;
//          k = -2;
//          break label370;
//          label741: localObject = new Cad_BaseDevice();
//          ((Cad_BaseDevice)localObject).drawRect.set(localCad_Rect1);
//          if ((baseDevice1 != null) && (_getjl(localCad_Rect1) > _getjl(baseDevice1.drawRect)))
//            ((Cad_BaseDevice)localObject).drawRect.set(baseDevice1.drawRect);
//          ((Cad_BaseDevice)localObject).drawRect.set(((Cad_BaseDevice)list1.get(i)).drawRect.getlinkpt(((Cad_BaseDevice)localObject).drawRect.pt2), ((Cad_BaseDevice)localObject).drawRect.pt2, true);
//          ((Cad_BaseDevice)list1.get(i)).linked = true;
//          localArrayList2.add(localObject);
//        }
//      }
//    }
  }

	public static boolean _selflink_mor_lines(ArrayList<Cad_BaseDevice> list1,
			ArrayList<ArrayList<Cad_BaseDevice>> list,
			ArrayList<Cad_BaseDevice> list2) {
		return false;
//		boolean result = false;
//		if ((list1 == null) || (list == null))
//			return false;
//		if (list.size() < 1)
//			return false;
//		list1.clear();
//		Log(LOG_INFO, "_selflink_mor_lines:"+"正在计算子干线拓扑连线,"+"list.size()="+list.size());
//		int i;
//		Object localObject;
//		double d1;
//		int j;
//		do {
//			if (list.size() <= 0) {
//				if (list1.size() <= 0)
//					break label218;
//				return true;
//			}
//			i = 0;
//			localObject = null;
//			d1 = 1000000.0D;
//			j = 0;
//			if (j < list.size())
//				break;
//			if (localObject != null) {
//				list1.add(localObject);
//				list1.addAll((Collection) list.get(i));
//				list.remove(i);
//			}
//			Oper_info.next(paramOper_info, list.size());
//		} while (Oper_info.can_run(paramOper_info));
//		return false;
//		
//		if (list1.size() == 0) {
//			list1.addAll((Collection) list.get(0));
//			list.remove(0);
//		}
//		while (true) {
//			j++;
//			break;
//			Cad_BaseDevice baseDevice = _lines_link_lines(
//					(ArrayList) list.get(j), list1, list2);
//			if (baseDevice != null) {
//				double d2 = _getjl(baseDevice.drawRect);
//				if (d2 < d1) {
//					d1 = d2;
//					i = j;
//					localObject = baseDevice;
//				}
//			}
//		}
//		label218: return false;
	}

	public static boolean _setpt_link(ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2, boolean pBool) {
		return false;
//		if (list1 == null)
//			return false;
//		int k;
//		if (list2 == null) {
//			k = 0;
//			if (k < list1.size())
//				;
//		}
//		while (true) {
//			return true;
//			((Cad_BaseDevice) list1.get(k)).linked = pBool;
//			k++;
//			break;
//			for (int i = 0; i < list2.size(); i++) {
//				int j = list1.indexOf(list2.get(i));
//				if (j >= 0)
//					((Cad_BaseDevice) list1.get(j)).linked = pBool;
//			}
//		}
	}

	public static boolean _ydjc(ArrayList<Cad_BaseDevice> list, Cad_BaseDevice paramEx_unbas, Cad_Rect rect)
  {
		   boolean bool = false;
		   if ((list == null) || (rect == null))
			   bool = false;
		   
		   Cad_BaseDevice baseDevice;
		   for(int i =0 ;i <list.size();i++){
			   baseDevice = (Cad_BaseDevice)list.get(i);
			   if ((paramEx_unbas == null) || (!baseDevice.equals(paramEx_unbas))){
			       bool = Cad_Rect._liInRect(rect, baseDevice.drawRect);
			       if (bool) 
				      break;
			   }
		   }
		   return bool;
//    if ((list == null) || (rect == null))
//    {
//      bool = false;
//      return bool;
//    }
//    boolean bool = false;
//    int i = 0;
//    label17: Cad_BaseDevice baseDevice;
//    if ((i < list.size()) && (!bool))
//    {
//      baseDevice = (Cad_BaseDevice)list.get(i);
//      if ((paramEx_unbas == null) || (!baseDevice.equals(paramEx_unbas)))
//        break label60;
//    }
//    while (true)
//    {
//      i++;
//      break label17;
//      break;
//      label60: bool = Cad_Rect._liInRect(rect, baseDevice.drawRect);
//    }
  }

	public static Cad_Point _yxjc(ArrayList<Cad_BaseDevice> list, Cad_Point point, Cad_Rect rect)
  {
		Cad_Point localObject = null;
		if ((list == null) || (rect == null))
			localObject =null;

	    Cad_Point point1;
	    for (int i =0 ; i<list.size();i++){
	    	 if (!rect.equals(((Cad_BaseDevice)list.get(i)).drawRect)){
	    		 point1 = Cad_Rect._getLLsjc(rect, ((Cad_BaseDevice)list.get(i)).drawRect);
	    		 if (point1 != null && !point1.equals(point)){
	    			 localObject = point; 
	    		 }
	    	 }
	    }
	    return localObject;
//    if ((list == null) || (rect == null))
//    {
//      localObject = null;
//      return localObject;
//    }
//    Object localObject = null;
//    int i = 0;
//    label17: Cad_Point point;
//    if ((i < list.size()) && (localObject == null))
//      if (!rect.equals(((Cad_BaseDevice)list.get(i)).drawRect))
//      {
//        point = Cad_Rect._getLLsjc(rect, ((Cad_BaseDevice)list.get(i)).drawRect);
//        if (point != null)
//        {
//          if (point != null)
//            break label85;
//          localObject = point;
//        }
//      }
//    while (true)
//    {
//      i++;
//      break label17;
//      break;
//      label85: if (!point.equals(point))
//        localObject = point;
//    }
  }

	 //判定存在交叉
	private static boolean _yxjc(ArrayList<Cad_BaseDevice> list, Cad_Point point, Cad_Rect rect, boolean pBool)
  {
		boolean bool = false;
	    if ((list == null) || (rect == null))
	    {
	      bool = false;
	    }
	    
	   // int i = 0;
	    Cad_Point point1;
	    for(int i=0; i < list.size();i++){
	    	 point1 = Cad_Rect._getLLsjc(rect, ((Cad_BaseDevice)list.get(i)).drawRect);
	    	 if (point1 != null){
	    		 if ((point1.equals(point)) || (((Cad_BaseDevice)list.get(i)).linked != pBool)){
	    			 bool =true;
	    			 if (bool)
	    				 break;
	    		 }
	    	 }
	    	 
	    }
	    return  bool;
	    
//    if ((list == null) || (rect == null))
//    {
//      bool = false;
//      return bool;
//    }
//    boolean bool = false;
//    int i = 0;
//    label20: Cad_Point point;
//    if ((i < list.size()) && (!bool))
//    {
//      point = Cad_Rect._getLLsjc(rect, ((Cad_BaseDevice)list.get(i)).drawRect);
//      if (point != null)
//      {
//        if (point != null)
//          break label86;
//        if (((Cad_BaseDevice)list.get(i)).linked != pBool);
//      }
//    }
//    for (bool = true; ; bool = true)
//      label86: 
//      do
//      {
//        i++;
//        break label20;
//        break;
//      }
//      while ((point.equals(point)) || (((Cad_BaseDevice)list.get(i)).linked != pBool));
  }

	public static boolean _zlxlxlk(ArrayList<Cad_BaseDevice> list1,
			ArrayList<Cad_BaseDevice> list2, ArrayList<Cad_BaseDevice> list3) {
		return false;
//		if (list3 == null)
//			return false;
//		if (list3.size() < 2)
//			return false;
//		if (list3.size() < 3) {
//			Cad_Rect localCad_Rect1 = new Cad_Rect(
//					((Cad_BaseDevice) list3.get(0)).drawRect);
//			Cad_Rect localCad_Rect2 = new Cad_Rect(
//					((Cad_BaseDevice) list3.get(1)).drawRect);
//			Cad_Point point1 = Cad_Rect
//					._getLLjc(localCad_Rect1, localCad_Rect2);
//			if (Cad_Rect._ptOnLine(localCad_Rect2, point1) == -1)
//				Cad_Rect._mp_line(localCad_Rect2, point1);
//			Cad_Rect._mp_line(localCad_Rect1, point1);
//			((Cad_BaseDevice) list3.get(0)).drawRect.set(localCad_Rect1);
//			((Cad_BaseDevice) list3.get(1)).drawRect.set(localCad_Rect2);
//			return true;
//		}
//		int i = 0;
//		for (i = 0;; i++) {
//			if (i >= -1 + list3.size())
//				return true;
//			if (!((Cad_BaseDevice) list3.get(i)).linked)
//				break;
//		}
//		Cad_Rect localCad_Rect3 = new Cad_Rect(
//				((Cad_BaseDevice) list3.get(i)).drawRect);
//		Cad_Rect localCad_Rect4 = new Cad_Rect(
//				((Cad_BaseDevice) list3.get(i + 1)).drawRect);
//		Cad_Rect localCad_Rect5 = ((Cad_BaseDevice) list3.get(i)).drawRect;
//		Cad_Rect localCad_Rect6 = ((Cad_BaseDevice) list3.get(i + 1)).drawRect;
//		Cad_Point point2 = Cad_Rect._getLLjc(localCad_Rect3, localCad_Rect4);
//		if (i == 0) {
//			Cad_Rect._mp_line(localCad_Rect3, point2);
//			localCad_Rect4.pt1.copy(point2);
//		}
//		while (true) {
//			double d = (_getjl(localCad_Rect3) + _getjl(localCad_Rect4))
//					/ (_getjl(localCad_Rect5) + _getjl(localCad_Rect6));
//			if ((_ydjc(list1, null, localCad_Rect4))
//					|| (_yxjc(list2, point2, localCad_Rect4, false))
//					|| (_ydjc(list1, null, localCad_Rect3))
//					|| (_yxjc(list2, point2, localCad_Rect3, false))
//					|| (d > 2.0D) || (double_equals(d, 2.0D)))
//				break;
//			((Cad_BaseDevice) list3.get(i)).drawRect.set(localCad_Rect3);
//			((Cad_BaseDevice) list3.get(i)).linked = true;
//			((Cad_BaseDevice) list3.get(i + 1)).drawRect.set(localCad_Rect4);
//			break;
//			if (i == -2 + list3.size()) {
//				localCad_Rect3.pt2.copy(point2);
//				Cad_Rect._mp_line(localCad_Rect4, point2);
//			} else {
//				localCad_Rect3.pt2.copy(point2);
//				localCad_Rect4.pt1.copy(point2);
//			}
//		}
	}

	public static boolean double_equals(double db1, double db2) {
		return Math.abs(db1 - db2) < 1.E-009D;
	}

	public static String get_fw_jd(Cad_Point[] paramArrayOfEx_dpoint,
			double[] paramArrayOfDouble) {
//		if ((paramArrayOfEx_dpoint == null) || (paramArrayOfDouble == null))
//			return " ";
//		if ((paramArrayOfEx_dpoint[0] == null)
//				|| (paramArrayOfEx_dpoint[1] == null)
//				|| (paramArrayOfEx_dpoint[2] == null))
//			return " ";
//		paramArrayOfDouble[0] = 0.0D;
//		Cad_Rect localCad_Rect = new Cad_Rect(paramArrayOfEx_dpoint[1],
//				paramArrayOfEx_dpoint[2]);
//		if (Cad_Rect._ptOnLine(localCad_Rect, paramArrayOfEx_dpoint[0]) != 0) {
//			paramArrayOfDouble[0] = 0.0D;
//			return " ";
//		}
//		Cad_Point point = Cad_Rect._getPLcz(localCad_Rect,
//				paramArrayOfEx_dpoint[0]);
//		if (point != null) {
//			int i = Cad_Rect._ptOnLine(localCad_Rect, point);
//			int j = 0;
//			if (i == 1)
//				j = 1;
//			if ((Cad_Rect._ptOnLine(localCad_Rect, point) == -1)
//					&& (_getjl(paramArrayOfEx_dpoint[2], point) > _getjl(
//							paramArrayOfEx_dpoint[1], point)))
//				j = 1;
//			int k = 1;
//			double d1;
//			double d2;
//			if (double_equals(localCad_Rect.size().cx, 0.0D)) {
//				if (paramArrayOfEx_dpoint[0].x > paramArrayOfEx_dpoint[2].x)
//					k = 0;
//				d1 = _getjl(paramArrayOfEx_dpoint[0], point);
//				d2 = _getjl(paramArrayOfEx_dpoint[0], paramArrayOfEx_dpoint[2]);
//				if (!double_equals(d1, d2))
//					break label407;
//				paramArrayOfDouble[0] = 90.0D;
//			}
//			while (true) {
//				if (j != 0)
//					paramArrayOfDouble[0] = (180.0D - paramArrayOfDouble[0]);
//				if (k == 0)
//					break label424;
//				return "左";
//				if (double_equals(localCad_Rect.size().cy, 0.0D)) {
//					if (paramArrayOfEx_dpoint[0].y >= paramArrayOfEx_dpoint[2].y)
//						break;
//					k = 0;
//					break;
//				}
//				if ((paramArrayOfEx_dpoint[1].y - paramArrayOfEx_dpoint[2].y)
//						/ (paramArrayOfEx_dpoint[1].x - paramArrayOfEx_dpoint[2].x) > 0.0D) {
//					if (paramArrayOfEx_dpoint[1].x < paramArrayOfEx_dpoint[2].x) {
//						if (paramArrayOfEx_dpoint[0].x <= point.x)
//							break;
//						k = 0;
//						break;
//					}
//					if (paramArrayOfEx_dpoint[0].x >= point.x)
//						break;
//					k = 0;
//					break;
//				}
//				if (paramArrayOfEx_dpoint[1].x > paramArrayOfEx_dpoint[2].x) {
//					if (paramArrayOfEx_dpoint[0].x <= point.x)
//						break;
//					k = 0;
//					break;
//				}
//				if (paramArrayOfEx_dpoint[0].x >= point.x)
//					break;
//				k = 0;
//				break;
//				label407: paramArrayOfDouble[0] = Math.toDegrees(Math.asin(d1
//						/ d2));
//			}
//			label424: return "右";
//		}
		return " ";
	}

	public String Draw(boolean pBool) {
		String result;
		String str1;

		if (this.rect == null)
			return "";

		if (pBool) {
			Object[] objs = new Object[1];
			objs[0] = this.layerName;

			// setcur_layer = layer s %1$s
			str1 = String.format(Cad_BaseInfo.CAD_setcur_layer, objs);
		}

		// StringBuilder localStringBuilder1 = new
		// StringBuilder(String.valueOf(str1));

		Object[] objs2 = new Object[4];
		objs2[0] = Double.valueOf(this.rect.pt1.x);
		objs2[1] = Double.valueOf(this.rect.pt1.y);
		objs2[2] = Double.valueOf(this.rect.pt2.x);
		objs2[3] = Double.valueOf(this.rect.pt2.y);
		// draw_line = line %1$f,%2$f %3$f,%4$f
		String str3 = String.format(Cad_BaseInfo.CAD_draw_line, objs2);

		if (this.showName.length() > 0) {
//			Cad_Rect rect = gettextjd();
			Cad_Rect rect = this.rect;
			Object[] objs3 = new Object[2];
			objs3[0] = Double.valueOf(rect.pt2.x);
			objs3[1] = Double.valueOf(rect.pt2.y);
			String.format("%1$f,%2$f", objs3);
			StringBuilder localStringBuilder2 = new StringBuilder(
					String.valueOf(str3));

			// draw_text_jd = text %1$f,%2$f %3$f %4$f,%5$f %6$s
			String str4 = Cad_BaseInfo.CAD_draw_text_jd;
			Object[] objs4 = new Object[6];
			objs4[0] = Double.valueOf(rect.pt1.x);
			objs4[1] = Double.valueOf(rect.pt1.y);
			objs4[2] = Double.valueOf(0.8D);
			objs4[3] = Double.valueOf(rect.pt2.x);
			objs4[4] = Double.valueOf(rect.pt2.y);
			objs4[5] = this.showName;
			//str3 = String.format(str4, objs4);
		}
		return str3;
	}

	public Cad_Rect gettextjd() {
		Cad_Rect rect = new Cad_Rect(this.rect);
		double d1 = 0.8D * (0.96D * this.deviceName.length());
		double d2 = (_getjl(this.rect.pt1, this.rect.pt2) - d1) / 2.0D;
		double d3 = 0.0D;

		if (this.rect.size().cx != 0.0D && this.rect.size().cy != 0.0D) {
			d3 = (this.rect.pt1.x - this.rect.pt2.x)
					/ (this.rect.pt1.y - this.rect.pt2.y);
		}

		Cad_Point point1 = this.rect.pt1;
		if (this.rect.pt1.x < this.rect.pt2.x) {
			point1 = this.rect.pt1;
		}

		// Cad_Point point2 = this.rect.pt2;

		for (Cad_Point point2 = this.rect.pt2;; point2 = this.rect.pt1) {

			rect.set(point1, point2);
			Cad_Point point3 = _getpoint(rect, point1, d2);
			rect.pt1.copy(point3);
			if (d3 <= 0.0D)
				break;
			rect.moveof(-0.5D, 0.0D);
			// return localCad_Rect;
			point1 = this.rect.pt2;
		}
		rect.moveof(0.5D, 0.0D);
		return rect;

		// for (Cad_Point point2 = this.rect.pt2;; point2 = this.rect.pt1) {
		//
		// rect.set(point, point2);
		// Cad_Point point3 = _getpoint(rect, point, d2);
		// rect.pt1.copy(point3);
		// if (d3 <= 0.0D)
		// break;
		// rect.moveof(-0.5D, 0.0D);
		// // return localCad_Rect;
		// point = this.rect.pt2;
		// }
		// rect.moveof(0.5D, 0.0D);
		// return rect;
	}

	public void moveof(Cad_Point point) {
		this.rect.moveof(point);
	}

	public void set(String deviceName, String showName, String paramString3,
			String layerName, String lineName, int lineType, Cad_Rect rect) {
		this.deviceName = deviceName;
		this.showName = showName;
		this.same_obj = paramString3;
		this.layerName = layerName;
		this.lineName = lineName;
		this.line_type = lineType;
		this.rect.pt1.copy(rect.pt1);
		this.rect.pt2.copy(rect.pt2);
		this.rect.rectType = 1;
		if (layerName.equals("电缆")) {
			this.line_type = 2;
			if (this.same_obj.length() <= 0)
				this.usesame = false;
			return;
		}
		if (layerName.equals("导线"))
			this.line_type = 1;  //导线
		else
			this.line_type = lineType;
	}
}

/*
 * Location: C:\Users\Survival\Desktop\APP\jd-gui\classes_dex2jar.jar Qualified
 * Name: com.LVDIA.Cad_Line JD-Core Version: 0.6.2
 */